<!doctype html>
{% extends "base.html" %}
{% block title %}Mysql{% endblock title %}

{% block page2_show %}show{% endblock page2_show %}
{% block page2.3_active %}active{% endblock page2.3_active %}

{% block main_content %}
<div class="col-12 col-lg-12">
    <div class="card">
        <div class="card-header">
            <ul class="nav nav-pills card-header-pills pull-right" role="tablist">
                <li class="nav-item">
                    <a class="nav-link active" data-toggle="tab" href="#tab-1">已有资产Mysql管理</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" data-toggle="tab" href="#tab-2">通用Mysql管理</a>
                </li>
            </ul>
        </div>
        <div class="card-body">
            <div class="tab-content">
                <div class="tab-pane fade show active" id="tab-1" role="tabpanel">
                    
                    <form method="post" action="/mysqlbyhost">
                        <div class="form-group row">
                            <label class="col-form-label col-sm-2 text-sm-right pt-sm-0">选择主机：</label>
                            <div class="col-sm-5">
                                <select class="custom-select mb-3" name="hostname">
                                    {% for host in hosts %}
                                        <option value="{{host}}">{{host}}</option>
                                    {% endfor %}
                                </select>
                            </div>
                        </div>
                        <div class="form-group row">
                            <label class="col-form-label col-sm-2 text-sm-right">Mysql端口：</label>
                            <div class="col-sm-5">
                                <input type="number" name="port" class="form-control" required="" value="3306">
                            </div>
                        </div>
                        <div class="form-group row">
                            <label class="col-form-label col-sm-2 text-sm-right">用户名：</label>
                            <div class="col-sm-5">
                                <input type="text" name="user" class="form-control" required="">
                            </div>
                        </div>

                        <div class="form-group row">
                            <label class="col-form-label col-sm-2 text-sm-right">密码：</label>
                            <div class="col-sm-5">
                                <input type="password" name="password" class="form-control"  required="">
                            </div>
                        </div>

                        <div class="form-group row">
                            <label class="col-form-label col-sm-2 text-sm-right">选择数据库：</label>
                            <div class="col-sm-5">
                                <input type="text" name="database" class="form-control" required="">
                            </div>
                        </div>

                        <div class="form-group row">
                            <label class="col-form-label col-sm-2 text-sm-right pt-sm-0">执行类型：</label>
                            <div class="col-sm-5">
                                <select class="custom-select mb-3" name="type">
                                        <option value="1">单条查询</option>
                                        <option value="99">多条查询</option>
                                        <option value="0">插入</option>
                                </select>
                            </div>
                        </div>

                        <div class="form-group row">
                            <label class="col-form-label col-sm-2 text-sm-right">sql语句：</label>
                            <div class="col-sm-8">
                                <textarea class="form-control" name="sql" required="" rows="3"></textarea>
                            </div>
                        </div>
                        
                        <div class="form-group row">
                            <div class="col-sm-10 ml-sm-auto">
                                <button type="submit" class="btn btn-primary">提 交</button>
                                <p>{{ message }}</p>
                            </div>
                        </div>
                    </form>

                </div>
                
                <div class="tab-pane fade" id="tab-2" role="tabpanel">
                    <form method="post" action="/mysqlbyip">
                    
                        <div class="form-group row">
                            <label class="col-form-label col-sm-2 text-sm-right">MySQL ip</label>
                            <div class="col-sm-5">
                                <input type="text" name="ip" class="form-control" required="">
                            </div>
                        </div>

                        <div class="form-group row">
                            <label class="col-form-label col-sm-2 text-sm-right">Mysql 端口</label>
                            <div class="col-sm-5">
                                <input type="number" name="port" class="form-control" required="" value="3306">
                            </div>
                        </div>

                        <div class="form-group row">
                            <label class="col-form-label col-sm-2 text-sm-right">用户名</label>
                            <div class="col-sm-5">
                                <input type="text" name="user" class="form-control" required="">
                            </div>
                        </div>

                        <div class="form-group row">
                            <label class="col-form-label col-sm-2 text-sm-right">密码</label>
                            <div class="col-sm-5">
                                <input type="password" name="password" class="form-control" required="">
                            </div>
                        </div>

                        
                        <div class="form-group row">
                            <label class="col-form-label col-sm-2 text-sm-right">数据库：</label>
                            <div class="col-sm-5">
                                <input type="text" name="database" class="form-control" required="">
                            </div>
                        </div>

                        <div class="form-group row">
                            <label class="col-form-label col-sm-2 text-sm-right pt-sm-0">执行类型：</label>
                            <div class="col-sm-5">
                                <select class="custom-select mb-3" name="type">
                                        <option value="1">单条查询</option>
                                        <option value="99">多条查询</option>
                                        <option value="0">插入</option>
                                </select>
                            </div>
                        </div>

                        <div class="form-group row">
                            <label class="col-form-label col-sm-2 text-sm-right">sql语句：</label>
                            <div class="col-sm-8">
                                <textarea class="form-control" name="sql" required="" rows="3"></textarea>
                            </div>
                        </div>
                        
                        <div class="form-group row">
                            <div class="col-sm-10 ml-sm-auto">
                                <button type="submit" class="btn btn-primary">提 交</button>
                                <p>{{ message }}</p>
                            </div>
                        </div>

                    </form>
                </div>
            </div>
        </div>
    </div>
</div>

<div class="col-12">
    <div class="card">
        <div class="card-header">
            <h5 class="card-title">查询结果</h5>
            <h6 class="card-subtitle text-muted">这里将会展示出列表型查询的结果</h6>
            </div>
        <div class="card-body">
            <table id="datatables-multi" class="table table-striped" style="width:100%">
                <thead>
                    <tr>
                        {% for title in restitle %}
                            <th>{{ title }}</th>
                        {% endfor %}
                    </tr>
                </thead>
                <tbody>
                    {% for list in reslist %}
                        <tr>
                        {% for item in list %}
                            <td>{{ item }}</td>
                        {% endfor %}
                        </tr>
                    {% endfor %}
                </tbody>
            </table>
        </div>
    </div>
</div>

{% endblock main_content %}

{% block script %}
<script src="/assets/libs/datatables/datatables.min.js"></script>
<script>
    var datatablesMulti = $("#datatables-multi").DataTable({
        language: { // ajax 获取语言文件
            "url": "assets/libs/datatables/Chinese.json"
        },
        select: {
            style: "multi"
        }
    });
</script>
{% endblock script %}